import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class FormTestController extends StatefulWidget {
  FormTestController({Key key}) : super(key: key);

  @override
  _FormTestControllerState createState() => _FormTestControllerState();
}

class _FormTestControllerState extends State<FormTestController> {
  TextEditingController usernameController = new TextEditingController();

  String username = '';
  String password = '';

  int sex = 1;

  bool fang = false;

  bool isdialedLogin = true;
  @override
  void initState() {
    super.initState();
    //usernameController.text = "初始值";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomPadding: false,
        backgroundColor: Colors.white,
        appBar: AppBar(
          brightness: Brightness.dark,
          iconTheme: IconThemeData(color: Colors.white),
          title: Text(
            "表单控制器",
            style: TextStyle(color: Colors.white),
          ),
          backgroundColor: Colors.red,
        ),
        body: Padding(
            padding: EdgeInsets.all(20.0),
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  TextField(
                    controller: usernameController,
                    onChanged: (value) {
                      setState(() {
                        username = value;
                      });
                    },
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.all(10),
                      hintText: "请输入用户名",
                      // border:OutlineInputBorder(
                      //   //borderSide: BorderSide.none
                      // )
                    ),
                  ),
                  SizedBox(height: 20),
                  TextField(
                    onChanged: (value) {
                      setState(() {
                        password = value;
                      });
                    },
                    maxLength: 10,
                    obscureText: true,
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.all(10),
                      hintText: "请输入密码",
                      // border:OutlineInputBorder(
                      //   //borderSide: BorderSide.none
                      // )
                    ),
                  ),
                  SizedBox(height: 20),
                  Container(
                    child: FlatButton(
                        child: Text("登录"),
                        color: Colors.yellow,
                        textColor: Colors.blue,
                        disabledTextColor: Colors.black38,
                        disabledColor: Colors.black12,
                        splashColor: Colors.yellow,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(8)),
                        onPressed: username.isNotEmpty && password.isNotEmpty
                            ? () {
                                print(username);
                              }
                            : null),
                  ),
                  SizedBox(height: 20),
                  Text("Checkbox"),
                  Row(
                    children: <Widget>[
                      Checkbox(
                        value: this.fang,
                        activeColor: Colors.red,
                        onChanged: (bool value) {
                          setState(() {
                            this.fang = value;
                          });
                        },
                      ),
                    ],
                  ),
                  Divider(),
                  Text("CheckboxListTile"),
                  CheckboxListTile(
                    value: this.fang,
                    activeColor: Colors.red,
                    onChanged: (bool value) {
                      setState(() {
                        this.fang = value;
                      });
                    },
                    title: Text("标题"),
                    subtitle: Text("副标题"),
                    //secondary: Icon(Icons.home),
                  ),
                  Text("radio"),
                  Row(
                    children: <Widget>[
                      Text("男"),
                      Radio(
                        value: 1,
                        onChanged: (value) {
                          setState(() {
                            this.sex = value;
                          });
                        },
                        groupValue: this.sex,
                      ),
                      Text("女"),
                      Radio(
                        value: 2,
                        onChanged: (value) {
                          setState(() {
                            this.sex = value;
                          });
                        },
                        groupValue: this.sex,
                      )
                    ],
                  ),
                  Text("Switch"),
                  Row(
                    children: <Widget>[
                      CupertinoSwitch(
                        value: this.fang,
                        onChanged: (bool value) {
                          setState(() {
                            this.fang = value;
                          });
                        },
                      )
                    ],
                  )
                ],
              ),
            )));
  }
}
